﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.BLL.Tbl;
using HKEA.CMS.Core.Utility;

namespace WebApplication
{
    public partial class Jump :BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string strid=Request.QueryString["loginid"];
                int loginuid = 0;
                if (!string.IsNullOrEmpty(strid) && int.TryParse(strid, out loginuid) && loginuid > 0)
                {
                    if (Request.UrlReferrer != null)
                    {
                        string strReferrer = Request.UrlReferrer.Host;
                        if (!string.IsNullOrEmpty(strReferrer))
                        {
                            int i = strReferrer.IndexOf(ConfigurationManager.GetMemberLoginFrom());
                            if (i != -1)
                            {
                                if (Request.QueryString["type"] == "out")
                                {
                                    Session[Constant.SessionName.MemberLoginUID] = null;
                                    Session[Constant.SessionName.Customer] = null;
                                    Response.Redirect("/M_Basicinformation.aspx");
                                }
                                tblCust_WebLogin loginENT = new tblCust_WebLogin();
                                tblCust_WebLoginBLL loginBLL = new tblCust_WebLoginBLL();
                                loginENT.CustWebLoginUID = loginuid;
                                loginENT = loginBLL.GetENT(loginuid);
                                if (loginENT != null && loginENT.Status == 1)
                                {
                                    tblCustomer customer = new tblCustomer();
                                    tblCustomerBLL custBLL = new tblCustomerBLL();
                                    customer.CustomerUID = Convert.ToInt32(loginENT.CustomerUID);
                                    customer.Deleted = 0;
                                    customer = custBLL.GetEntity(customer);
                                    if (customer != null)
                                    {
                                        SetMemberLoginUIDToSession(loginuid);
                                        SetCustomerToSession(customer);
                                        Response.Redirect("/M_Basicinformation.aspx");
                                    }
                                    else
                                    { Label1.Text = ResourceManage.GetResourceString("msg200018"); }
                                }
                                else
                                { Label1.Text = ResourceManage.GetResourceString("msg200018"); }
                            }
                        }
                    }
                }
            }
        }
    }
}